home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS05.ADF / IFF / ilbmdump.c < prev    next >
C/C++ Source or Header  |  1986-04-20  |  5KB  |  132 lines

  1.  
  2. /*--------------------------------------------------------------*/
  3. /*                                      */
  4. /* ILBMDump.c: reads in ILBM, prints out ascii representation,   */
  5. /*  for including in C files.                          */
  6. /*                                                              */
  7. /* By Jerry Morrison and Steve Shaw, Electronic Arts.           */
  8. /* This software is in the public domain.                       */
  9. /*                                                              */
  10. /* This version for the Commodore-Amiga computer.               */
  11. /*                                                              */
  12. /*  Callable from CLI ONLY                        */
  13. /*  Jan 31, 1986                             */
  14. /*--------------------------------------------------------------*/
  15.  
  16.  
  17.  
  18. #include "iff/intuall.h"
  19. #include "libraries/dos.h"
  20. #include "libraries/dosextens.h"
  21. #include "iff/ilbm.h"
  22. #include "iff/readpict.h"
  23. #include "iff/remalloc.h"
  24.  
  25. #undef NULL
  26. #include "lattice/stdio.h"
  27. /*----------------------------------------------------------------------*/
  28. /*   Iff error messages                           */
  29. /*----------------------------------------------------------------------*/
  30.  
  31. char MsgOkay[] = { "----- (IFF_OKAY) A good IFF file." };
  32. char MsgEndMark[] = {"----- (END_MARK) How did you get this message??" };
  33. char MsgDone[] = { "----- (IFF_DONE) How did you get this message??" };
  34. char MsgDos[] = { "----- (DOS_ERROR) The DOS gave back an error." };
  35. char MsgNot[] = { "----- (NOT_IFF) not an IFF file." };
  36. char MsgNoFile[] = { "----- (NO_FILE) no such file found." };
  37. char MsgClientError[] = {"----- (CLIENT_ERROR) IFF Checker bug."};
  38. char MsgForm[] = { "----- (BAD_FORM) How did you get this message??" };
  39. char MsgShort[] = { "----- (SHORT_CHUNK) How did you get this message??" };
  40. char MsgBad[] = { "----- (BAD_IFF) a mangled IFF file." };
  41.  
  42. /* MUST GET THESE IN RIGHT ORDER!!*/
  43. char *IFFPMessages[-LAST_ERROR+1] = {
  44.     /*IFF_OKAY*/  MsgOkay,
  45.     /*END_MARK*/  MsgEndMark,
  46.     /*IFF_DONE*/  MsgDone,
  47.     /*DOS_ERROR*/ MsgDos,
  48.     /*NOT_IFF*/   MsgNot,
  49.     /*NO_FILE*/   MsgNoFile,
  50.     /*CLIENT_ERROR*/ MsgClientError,
  51.     /*BAD_FORM*/  MsgForm,
  52.     /*SHORT_CHUNK*/  MsgShort,
  53.     /*BAD_IFF*/   MsgBad
  54.     };
  55.  
  56. /* this returns a string containing characters after the
  57.       last '/' or ':' */
  58. GetSuffix(to, fr) UBYTE *to, *fr; {
  59.     int i;
  60.     UBYTE c,*s = fr;
  61.     for (i=0; ;i++) {
  62.      c = *s++;
  63.      if (c == 0) break;
  64.      if (c == '/') fr = s;
  65.      else if (c == ':') fr = s;
  66.      }
  67.     strcpy(to,fr);
  68.     }
  69.  
  70. LONG GfxBase;
  71. struct BitMap bitmap = {0};
  72.  
  73. ILBMFrame ilbmFrame;     /* Top level "client frame".*/
  74.  
  75. /** main() ******************************************************************/
  76.  
  77. UBYTE defSwitch[] = "b";
  78.  
  79. void main(argc, argv)  int argc;  char **argv;  {
  80.     UBYTE *sw;
  81.     FILE *fp;
  82.     LONG iffp,file;
  83.     UBYTE name[40], fname[40];
  84.     GfxBase = (LONG)OpenLibrary("graphics.library",0);
  85.     if (GfxBase==NULL) exit(0);
  86.     
  87.     if (argc) {
  88.      /* Invoked via CLI.  Make a lock for current directory. */
  89.      if (argc < 2) {
  90.          printf("Usage from CLI: 'ILBMDump filename switch-string'\n");
  91.          printf(" where switch-string = \n");
  92.          printf("  <nothing> : Bob format (default)\n");
  93.          printf("  s         : Sprite format (with header and trailer words)\n");
  94.          printf("  sn        : Sprite format (No header and trailer words)\n");
  95.          printf("  a         : Attached sprite (with header and trailer)\n");
  96.          printf("  an        : Attached sprite (No header and trailer)\n");
  97.          printf(" Add 'c' to switch list to output CR's with LF's   \n");
  98.          }
  99.      else {
  100.          sw = (argc>2)? argv[2]: defSwitch;
  101.          
  102.          file = Open(argv[1], MODE_OLDFILE);
  103.          
  104.          if (file) {
  105.           iffp = ReadPicture(file, &bitmap, &ilbmFrame, ChipAlloc);
  106.           Close(file);
  107.           if (iffp != IFF_DONE) {
  108.               printf(" Couldn't read file %s \n", argv[1]);
  109.               printf("%s\n",IFFPMessages[-iffp]);
  110.               }
  111.           else {
  112.               printf(" Creating file %s.c \n",argv[1]);
  113.               GetSuffix(name,argv[1]);
  114.               strcpy(fname,argv[1]);
  115.               strcat(fname,".c");
  116.               fp = fopen(fname,"w");
  117.               BMPrintCRep(&bitmap,fp,name,sw);
  118.               fclose(fp);
  119.               }
  120.           }
  121.          else printf(" Couldn't open file: %s. \n", argv[1]);
  122.  
  123.          if (bitmap.Planes[0])  RemFree(bitmap.Planes[0]);
  124.  
  125.          printf("\n");
  126.          }
  127.      }
  128.     CloseLibrary(GfxBase);
  129.     exit(0);
  130.     }
  131.  
  132.